<!DOCTYPE html>
<html class="x-admin-sm">
    {include file="Admin/Public/head" title="评论列表" /}

    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a">首页</a>
                <a>评论管理</a>
                <a><cite>评论列表</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5">
                                <div class="layui-input-inline layui-show-xs-block">
                                  <input class="layui-input" placeholder="文章标题" name="title" value="{$param['title']}">
                                </div>
                                <div class="layui-input-inline layui-show-xs-block">
                                  <select name="state">
                                    <option value="">审核状态</option>
                                    <option value="0" {if $param['display'] == '0'}selected{/if}>未审核</option>
                                    <option value="1" {if $param['display'] == 1}selected{/if}>审核未通过</option>
                                    <option value="2" {if $param['display'] == 2}selected{/if}>审核已通过</option>
                                  </select>
                                </div>
                                <div class="layui-input-inline layui-show-xs-block">
                                  <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn layui-btn-danger" onclick="delAll()">
                                <i class="layui-icon"></i>批量删除</button>
                            <button class="layui-btn" onclick="audit(2)">
                                <i class="layui-icon"></i>批量审核通过</button>
                            <button class="layui-btn layui-btn-warm" onclick="audit(1)">
                                <i class="layui-icon"></i>批量审核不通过</button>
                        </div>
                        <div class="layui-card-body ">
                            <table class="layui-table layui-form">
                              <thead>
                                <tr>
                                  <th width="20">
                                    <input type="checkbox" class="checkFather" lay-skin="primary" lay-filter="allChoose">
                                  </th>
                                  <th width="70">ID</th>
                                  <th width="80">文章标题</th>
                                  <th>评论内容</th>
                                  <th width="80">评论时间</th>
                                  <th width="80">评论者ip</th>
                                  <th width="80">审核状态</th>
                              </thead>
                              <tbody class="x-cate">
                                {volist name="data['datas']" id="val" key="i"}
                                  <tr>
                                    <td>
                                      <input type="checkbox" class="checkChild" value="{$val['id']}" lay-skin="primary" lay-filter="itemChoose">
                                    </td>
                                    <td>{$val['id']}</td>
                                    <td>{$val['title']}</td>
                                    <td>{$val['comment']}</td>
                                    <td>{$val['comment_time']}</td>
                                    <td>{$val['ip']}</td>
                                    <td>{$val['state_text']}</td>
                                  </tr>
                                {/volist}
                              </tbody>
                            </table>
                        </div>
                        <div class="layui-card-body ">
                            <div class="page">
                                <div>
                                  {include file="Admin/Public/page" /}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        {include file="Admin/Public/checkAll" /}
        <script>
          layui.use(['form'], function(){
            let form = layui.form;
            checkAll(form);
          });
          $("#go").click(function(){
            let page = $("#goPage").val();
            if (page > 0 && page <= Number($(".num:last").text())) {
              location.href="{$url}?page="+page+"&{$data['query']|raw}"
            }
          })

          function delAll () {
            let ids = getCheckValues();
            
            layer.confirm('确认要删除吗？', function(index){
              layer.load(2);
              $.post("/admin/comments/delete", {id: ids}, function(data){
                layer.closeAll();
                if (data.code == 200) {
                  layer.msg(data.msg, {time: 1500}, function(){
                    location.reload();
                  })
                } else if (data.code) {
                  layer.msg(data.msg)
                }
              })
            });
          }
          function audit (state) {
            let ids = getCheckValues();
            
            layer.confirm('确认要审核吗？', function(index){
              layer.load(2);
              $.post("/admin/comments/audit", {id: ids, state: state}, function(data){
                layer.closeAll();
                if (data.code == 200) {
                  layer.msg(data.msg, {time: 1500}, function(){
                    location.reload();
                  })
                } else if (data.code) {
                  layer.msg(data.msg)
                }
              })
            });
          }
        </script>
    </body>
</html>